function popup(id, width, height, toolbar ,menubar, status){return pop_up(id, width, height, toolbar,menubar, status);}
function pop_up(id, width, height, toolbar ,menubar, status){
	if(id == "" || id == null) {
		return;
	}
	if (width == "" || width == null || height == "" || height == null) {
		width = 800;
		height = 600;
	}
	if(toolbar=="") toolbar="no";
	if(menubar=="") menubar="no";
	if(status=="") status="no";
	wx = (screen.width-width)/2;
	wy = (screen.height-height)/2;
	wnd=window.open(id,"_blank", "width="+width+",height="+height+",status="+status+",resizable=1,scrollbars=1,toolbar="+toolbar+",menubar="+menubar+", left="+wx+",top="+wy);
	return false;
}

function close_self(){
	if(window.opener){
		window.opener.location.reload();
	}
	window.close();
}

function close_control(location){
	if(window.opener){
		window.opener.location=location;
	}
	window.close();
}

opened=1;

function ret_selected(element){
	url="";
	title="";
	form=element.form;
	try{
		elements=form.elements;
		for(i=0;i<elements.length;i++){
			if(elements[i].checked){
				url=elements[i].value;
				title=elements.elements[url].value;
			}
		}
		if(url!=""){
			window.opener.navigator_call_back(url,title);
			window.close();
		}else{
			logging("No page selected!");
			return false;
		}
		return true;
	}catch(e){
		logging("Error ret_selected:"+e.message);
	}
}

function navigator_call_back(url,title){
	try{
		form=window.document.forms[0];
		form["url"].value=url;
		form["navigator_but"].value=title;
	}catch(e){
		logging("Error navigator_call_back:"+e.message);
	}
}

function grap_initialization(){
	try{
		var closebut=getElement("close_window_input");
		if(closebut&&!window.opener){
			closebut.style.display="none";
		}
	}catch(e){
		logging("Error grap_initialization:"+e.message);
	}
}

function scrollTop(){
	var ScrollTop = document.body.scrollTop;
	if(ScrollTop == 0){
		if(window.pageYOffset)
			ScrollTop = window.pageYOffset;
		else
			ScrollTop = (document.body.parentElement) ? document.body.parentElement.scrollTop : 0;
	}
	return ScrollTop;
}

//For debuging
function print_r(x,max,sep,l){ 
	l = l || 0; 
	max = max || 10; 
	sep = sep || ' '; 
	if (l > max) { return "[WARNING: Too much recursion]\n";} 
	var i, r = '', t = typeof x, tab = '';	
	if (x === null) { r += "(null)\n"; 
	}else if (t == 'object'){
		l++; 
		for(i=0;i<l;i++){ 
			tab+= sep;
		}
		if(x&&x.length){
			t='array';
		}
		r+='('+t+") :\n"; 
		for(i in x){ 
			try{ 
				r+=tab+'['+i+'] : '+print_r(x[i],max,sep,(l + 1));
			}catch(e){
				return "[ERROR: "+e+"]\n"; 
			}
		}
	}else{
		if(t =='string'){
			if(x==''){
				x='(empty)';
			}
		}
		r +='('+t+') '+x+"\n";
	}
	return r;
}

/*Cookie*/
function setCookie(name, value, expires, path, domain, secure) {
	var curCookie = name + "=" + escape(value) + ((expires) ? "; expires=" + expires.toGMTString() : "") + ((path) ? "; path=" + path : "") + ((domain) ? "; domain=" + domain : "") + ((secure) ? "; secure" : "");
	document.cookie = curCookie;
}

function getCookie(name) {
	var dc = document.cookie;
	var prefix = name + "=";
	var begin = dc.indexOf("; " + prefix);
	if(begin == -1) {
		begin = dc.indexOf(prefix);
		if(begin != 0)
			return null;
	}else{
		begin += 2;
	}
	var end = document.cookie.indexOf(";", begin);
	if (end == -1)end = dc.length;
	return unescape(dc.substring(begin + prefix.length, end));
}

function info(message){alert(message);}
function warn(message){alert(message);}
function error(message){alert(message);}

function numeric_semantic(num,words){
	num = num % 100;
	if( num > 20 ){
		num = num % 10;
	}
	if ( 1 == num ){
		return words[0];
	}else{
		if( !num ){
			return words[2];
		}else{
			if( num <= 4  ){
				return words[1];
			}else{
				return words[2];
			}
		}
	}
}